import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:dailypayagent/ui/page/coin/coin_record_list_page.dart';
import 'package:dailypayagent/ui/page/data/datasummary_page.dart';
import 'package:dailypayagent/ui/page/data/merchantcount_page.dart';
import 'package:dailypayagent/ui/page/data/salsmancount_page.dart';
import 'package:dailypayagent/ui/page/data/transitionlist_page.dart';
import 'package:dailypayagent/ui/page/personal/agentrate_page.dart';
import 'package:dailypayagent/ui/page/personal/merchantrate_page.dart';
import 'package:dailypayagent/ui/page/personal/salesmanager_page.dart';
import 'package:dailypayagent/ui/page/personal/update_pwd_page.dart';
import 'package:dailypayagent/ui/page/setting_page.dart';
import 'package:dailypayagent/ui/page/splash.dart';
import 'package:dailypayagent/ui/page/tab/tab_navigator.dart';
import 'package:dailypayagent/ui/page/user/login_page.dart';
import 'package:dailypayagent/ui/page/user/register_page.dart';
import 'package:dailypayagent/ui/widget/page_route_anim.dart';

class RouteName {
  static const String splash = 'splash';
  static const String tab = '/';
  static const String homeSecondFloor = 'homeSecondFloor';
  static const String login = 'login';
  static const String register = 'register';
  static const String articleDetail = 'articleDetail';
  static const String salesManager = 'salesManager';
  static const String setting = 'setting';
  static const String agentrate = 'agentrate';
  static const String coinRecordList = 'coinRecordList';
  static const String coinRankingList = 'coinRankingList';

  static const String merchantDefaultRate = 'merchantDefaultRate';
  static const String updatePwd = 'updatePwd';

  static const String dataSummary = 'dataSummary';
  static const String merchantCount = 'merchantCount';
  static const String transitionList = 'transitionList';
  static const String salsmanCount = 'salsmanCount';
}

class Router {
  static Route<dynamic> generateRoute(RouteSettings settings) {
    switch (settings.name) {
      case RouteName.splash:
        return NoAnimRouteBuilder(SplashPage());
      case RouteName.tab:
        return NoAnimRouteBuilder(TabNavigator());
      case RouteName.login:
        return NoAnimRouteBuilder(LoginPage());

      case RouteName.dataSummary:
        return CupertinoPageRoute(builder: (_) => DataSummary());
      case RouteName.merchantCount:
        return CupertinoPageRoute(builder: (_) => MerchantCount());
      case RouteName.transitionList:
        return CupertinoPageRoute(builder: (_) => TransitionList());
      case RouteName.salsmanCount:
        return CupertinoPageRoute(builder: (_) => SalsmanCount());

      case RouteName.salesManager:
        return CupertinoPageRoute(builder: (_) => SalesManager());
      case RouteName.agentrate:
        return CupertinoPageRoute(builder: (_) => AgentRatePage());
      case RouteName.merchantDefaultRate:
        return CupertinoPageRoute(builder: (_) => MerchantDeFaultRatePage());
      case RouteName.updatePwd:
        return CupertinoPageRoute(builder: (_) => UpdatePwdPage());
      case RouteName.register:
        return CupertinoPageRoute(builder: (_) => RegisterPage());
      case RouteName.setting:
        return CupertinoPageRoute(builder: (_) => SettingPage());
      case RouteName.coinRecordList:
        return CupertinoPageRoute(builder: (_) => CoinRecordListPage());
      default:
        return CupertinoPageRoute(
            builder: (_) => Scaffold(
                  body: Center(
                    child: Text('No route defined for ${settings.name}'),
                  ),
                ));
    }
  }
}

/// Pop路由
class PopRoute extends PopupRoute {
  final Duration _duration = Duration(milliseconds: 300);
  Widget child;

  PopRoute({@required this.child});

  @override
  Color get barrierColor => null;

  @override
  bool get barrierDismissible => true;

  @override
  String get barrierLabel => null;

  @override
  Widget buildPage(BuildContext context, Animation<double> animation,
      Animation<double> secondaryAnimation) {
    return child;
  }

  @override
  Duration get transitionDuration => _duration;
}
